<template>
	<view class="list-page" :style="loading ? 'opacity: 0;' : 'opacity: 1;'">
		<!--  v-model="dataList" @query="queryList" -->
		<!--  refresher-only @onRefresh="onRefresh" -->
		<pageTxt>
			<listTabCom class="listTabCom" :tabList="topTabListArr" @topTabClick="topTabClick" :current="topTabIndex"></listTabCom>
			<!-- 勘场管理 -->
			<siteSurveyManagement ref="siteSurveyManagement" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 1"></siteSurveyManagement>
			<!-- 设计管理 -->
			<designManagement ref="designManagement" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 2"></designManagement>
		</pageTxt>
	</view>
</template>

<script>
import siteSurveyManagement from './components/siteSurveyManagement/siteSurveyManagement.vue';
import designManagement from './components/designManagement/designManagement.vue';
export default {
	components: {
		designManagement,
		siteSurveyManagement
	},
	data() {
		return {
			loading: true,
			dataList: [],
			conentHeight: 0,
			topTabIndex: '-1',
			showIndex: 0,
			topTabList: [
				{
					name: '勘场管理',
					menu: '/kcgl',
					key: 1
				},
				{
					name: '设计管理',
					menu: '/sjgl',
					key: 2
				}
			],
			refreshItem: false, //刷新单个数据
			topTabListArr: []
		};
	},
	onShow() {
		this.$nextTick(() => {
			switch (Number(this.showIndex)) {
				case 1:
					if (!this.$refs.siteSurveyManagement) return;
					this.$refs.siteSurveyManagement.refreshItemFunc();
					break;
				case 2:
					if (!this.$refs.designManagement) return;
					this.$refs.designManagement.refreshItemFunc();
					break;
				default:
			}
		});
	},
	onLoad(option) {
		this.getHeight();
		// 菜单权限判断
		let topTabListArr = [];
		this.topTabList.forEach((item) => {
			if (this.$menuShow(item.menu)) {
				topTabListArr.push(item);
			}
		});
		this.topTabListArr = topTabListArr;

		this.$nextTick(() => {
			if (option.tabIndex) {
				let index = topTabListArr.findIndex((item) => {
					return item.key == option.tabIndex;
				});
				this.topTabIndex = index;
				this.showIndex = option.tabIndex;
			}
		});
	},
	methods: {
		getHeight() {
			// 创建节点查询
			let that = this;
			const systemInfo = uni.getSystemInfoSync();
			const query = uni.createSelectorQuery().in(that);
			query.select('.listTabCom').boundingClientRect();
			query.exec((res) => {
				that.conentHeight = systemInfo.screenHeight - (res[0].height + 20); //组件可用高度 20状态栏高度（动态获取高度不包含状态栏高度）
				setTimeout(() => {
					that.loading = false;
				}, 200);
			});
		},
		topTabClick(index) {
			this.topTabIndex = index;
			this.showIndex = this.topTabListArr[index].key;
		}
	}
};
</script>

<style lang="scss" scoped></style>
